package com.kamistoat.meimeistore.coupon.controller;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.kamistoat.meimeistore.coupon.entity.SpuBoundsEntity;
import com.kamistoat.meimeistore.coupon.service.SpuBoundsService;
import com.kamistoat.common.utils.PageUtils;
import com.kamistoat.common.utils.R;


/**
 * 商品spu积分设置
 *
 * @author kamistoat
 * @email linjianshanke@163.com
 * @date 2021-09-12 16:19:47
 */
@RestController
@RequestMapping("meimeistorecoupon/spubounds")
public class SpuBoundsController {
    @Autowired
    private SpuBoundsService spuBoundsService;

    /**
     * 根据SpuId查积分
     */
    @GetMapping("getBoundsBySpuId")
    public BigDecimal[] getBoundsBySpuId(@RequestParam Long spuId) {
        BigDecimal[] bounds = new BigDecimal[2];
        SpuBoundsEntity boundsEntity = spuBoundsService.getOne(new QueryWrapper<SpuBoundsEntity>().eq("spu_id", spuId));
        if (boundsEntity != null) {
            bounds[0] = boundsEntity.getGrowBounds();
            bounds[1] = boundsEntity.getBuyBounds();
        }
        return bounds;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("meimeistorecoupon:spubounds:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = spuBoundsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("meimeistorecoupon:spubounds:info")
    public R info(@PathVariable("id") Long id) {
        SpuBoundsEntity spuBounds = spuBoundsService.getById(id);

        return R.ok().put("spuBounds", spuBounds);
    }

    /**
     * 保存，也将被用于接收跨模通信保存SpuBoundsTo
     */
    @RequestMapping("/save")
    //@RequiresPermissions("meimeistorecoupon:spubounds:save")
    public R save(@RequestBody SpuBoundsEntity spuBounds) {
        spuBoundsService.save(spuBounds);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("meimeistorecoupon:spubounds:update")
    public R update(@RequestBody SpuBoundsEntity spuBounds) {
        spuBoundsService.updateById(spuBounds);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("meimeistorecoupon:spubounds:delete")
    public R delete(@RequestBody Long[] ids) {
        spuBoundsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
